import { Injectable } from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';

@Injectable()
export class HttpInterceptorService implements HttpInterceptor {
  intercept ( req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    let cloneReq = req;
    console.log(req.url);
    cloneReq = req.clone({
      headers:  req.headers.set('Authorization', 'Basic dnMtYW5ndWxhcjpzZWNyZXQ=')
    });
    if (localStorage.getItem('access_token')) {
      cloneReq = req.clone({
        params: req.params.set('access_token', localStorage.getItem('access_token'))
      });
    }
    return next.handle(cloneReq);
  }
  constructor() { }

}
